//
//  GRViewController.m
//  GRFMDownloader
//
//  Created by GR on 01/11/2018.
//  Copyright (c) 2018 GR. All rights reserved.
//

#import "GRViewController.h"
#import "GRFMDownloader.h"
@interface GRViewController ()
@property (strong, nonatomic) GRFMDownloader *downloader;
@property (weak, nonatomic) IBOutlet UIButton *startBtn;
@property (weak, nonatomic) IBOutlet UIButton *pauseBtn;
@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;
@property (weak, nonatomic) IBOutlet UIButton *deleteBtn;

@property (weak, nonatomic) NSTimer *timer;
@end

@implementation GRViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	
//    [self timer];
    self.downloader = [[GRFMDownloader alloc] init];
}

- (void)update
{
    NSLog(@"%zd", self.downloader.state);
}

- (NSTimer *)timer
{
    if (!_timer) {
        NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(update) userInfo:nil repeats:YES];
        [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
        _timer = timer;
    }
    return _timer;
}

- (IBAction)deleteAction:(id)sender {
    [self.downloader cancelAndClear];
}

- (IBAction)cancelAction:(id)sender {
    [self.downloader cancel];
}

- (IBAction)pauseAction:(id)sender {
    [self.downloader pause];
}

- (IBAction)startAction:(id)sender {
//    [self.downloader download:[NSURL URLWithString:@"http://120.25.226.186:32812/resources/videos/minion_01.mp4"]];
//    [self.downloader download:[NSURL URLWithString:@"http://120.25.226.186:32812/resources/videos/minion_01.mp4"] info:^(long long totalSize) {
//        NSLog(@"info - %zd", totalSize);
//    } progressChange:^(float progress) {
//        NSLog(@"progress - %f", progress);
//    } stateChange:^(GRFMDownloaderState state) {
//        NSLog(@"%zd", state);
//    } success:^(NSString *cachePath) {
//        NSLog(@"success - %@", cachePath);
//    } faile:^{
//        NSLog(@"faile");
//    }];
}

@end
